/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package millenium3dchess;

/**
 *
 * @author Kenneth
 */
import java.util.ArrayList;
import millenium3dchess.Player.Error;

public class ConsoleDisplay implements Display {

    @Override
    public void display() {
        System.out.println("       Level 1            Level 2            Level 3      ");
        for (int i = 7; i >= 0; i--) {
            System.out.print(i + 1 + "| ");
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 8; k++) {
                    display(Game.getBoard()[j][k][i]);
                    if (k == 7 && j != 2) {
                        System.out.print(i + 1 + "| ");
                    } else if (k == 7 && j == 2) {
                        System.out.print("|");
                    }
                }
            }
            System.out.println("");
        }
        System.out.println("   a b c d e f g h    a b c d e f g h    a b c d e f g h");
    }

    @Override
    public void display(GameSquare gameSquare) {
        System.out.print(gameSquare.getChessman().toString());
    }

    @Override
    public void displayPotentialMoves(GameSquare gameSquare) {
        gameSquare.getChessman().updateMoveList();
        ArrayList<GameSquare> squares = gameSquare.getChessman().moveList;
        System.out.println("       Level 1            Level 2            Level 3      ");
        for (int i = 7; i >= 0; i--) {
            System.out.print(i + 1 + "| ");
            for (int j = 0; j < 3; j++) {
                for (int k = 0; k < 8; k++) {
                    if (squares.contains(Game.getBoard()[j][k][i])) {
                        System.out.print("! ");
                    } else if (Game.getBoard()[j][k][i].equals(gameSquare)) {
                        System.out.print("+ ");
                    } else {
                        display(Game.getBoard()[j][k][i]);
                    }
                    if (k == 7 && j != 2) {
                        System.out.print(i + 1 + "| ");
                    } else if (k == 7 && j == 2) {
                        System.out.print("|");
                    }
                }
            }
            System.out.println("");
        }
        System.out.println("   a b c d e f g h    a b c d e f g h    a b c d e f g h");
    }

    @Override
    public void handlePlayerError(Error error) {
        System.out.println(error.getDescription());
    }

    @Override
    public void handleError(String error) {
        System.out.println(error);
    }
}
